package com.youwe.dao.module;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.youwe.interfaces.dao.demo.BookDao;
import com.youwe.model.demo.Book;

@RunWith(SpringRunner.class)
@SpringBootTest()
public class BookDaoImplTesting {
	
	@Autowired
	private BookDao bookDao;
	
	@Test
	public void getBook_Test() {
		Book book = new Book();
		book.setId("one");;
		book = bookDao.getBook(book);
		assertThat(book.getName()).isEqualTo("《钢铁是怎么样炼成的》");
	}
	
	@Test
	public void addBook_Test() {
		Book book = new Book();
		book.setId("ten");
		book.setName("《百万富翁》");
		book.setPrice(56.00);
		bookDao.addBook(book);
		
		Book conBook = new Book();
		conBook.setId("ten");
		assertThat(bookDao.getBook(conBook).getName()).isEqualTo("《百万富翁》");
	}
	
	@Test
	public void getAllBook_Test() {
		List<Book> bookList = bookDao.getAllBook();
		assertThat(bookList.size()).isGreaterThan(0);
		for(Book book : bookList) {
			System.out.println(book.toString());
		}
	}

}
